package space.xxhui.DAO.imp;

import java.util.List;

import org.springframework.orm.hibernate5.support.HibernateDaoSupport;

import space.xxhui.DAO.UserDao;
import space.xxhui.POJO.UserEntity;

public class ImpUserDAO extends HibernateDaoSupport implements UserDao {
	public UserEntity checkUser(UserEntity user) {
        String hql="from UserEntity u where u.name=? and u.pwd=?";
        List<UserEntity> list = (List<UserEntity>) this.getHibernateTemplate().find(hql,new String[]{user.getName(),user.getPwd()});
        if(list!=null&&!list.isEmpty()&&list.size()==1){
            return list.get(0);
        }
        return null;
    }

    public void addUser(UserEntity user) {
        this.getHibernateTemplate().save(user);
    }

    public List<UserEntity> queryAllUser() {
        return (List<UserEntity>) getHibernateTemplate().find("from UserEntity ");
    }
}
